package com.xayy.mgt.model;

import cn.kawins.mybatis.base.BaseModel;
import cn.kawins.mybatis.interceptor.FillingCreateTime;
import cn.kawins.mybatis.interceptor.InsertAutoFilling;
import cn.kawins.mybatis.interceptor.UpdateAutoFilling;
import cn.kawins.mybatis.util.SnowflakeId;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.xayy.mgt.enums.ProjectItemEnum;
import com.xayy.mgt.enums.ResultItemEnum;
import io.swagger.annotations.ApiModelProperty;
import tk.mybatis.mapper.annotation.KeySql;

import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.util.Date;
import lombok.*;

/**
 * 影响表(HistoryInfluence)实体类
 *
 * @author zhangxa
 * @since 2023-08-29 11:39:58
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "health_xw.t_history_influence")
@EqualsAndHashCode(callSuper = true)
public class HistoryInfluence extends BaseModel<Long> {
    @Id
    @ApiModelProperty(value = "主键")
    @Column(name = "id")
    @KeySql(genId = SnowflakeId.class)
    @JsonSerialize(using = ToStringSerializer.class)
    private Long id;

    /**
     * 部件
     */
    @Column(name = "components")
    @ApiModelProperty(value = "部件")
    private String components;

    /**
     * 部件
     */
    @Column(name = "node_id")
    @ApiModelProperty(value = "部件id")
    private Long componentsId;
    /**
     * 指标名称
     */
    @Column(name = "metrics_name")
    @ApiModelProperty(value = "指标名称")
    private String metricsName;
    /**
     * 指标代号
     */
    @Column(name = "metrics_code")
    @ApiModelProperty(value = "指标代号")
    private String metricsCode;

    /**
     * 结果
     */
    @Column(name = "result")
    @ApiModelProperty(value = "功能项结果")
    private Integer result;

    @Transient
    private String resultString;

    public void setResult(Integer result) {
        this.result = result;
        this.resultString = ResultItemEnum.valueof(result);
    }

    public void getResultString(String resultString) {
        this.resultString = resultString;
        this.result = ResultItemEnum.valueof(resultString);
    }

    /**
     * 指标类别
     */
    @Column(name = "categories")
    @ApiModelProperty(value = "指标类别")
    private Integer categories;

    @Transient
    private String categoriesString;

    public void setCategories(Integer categories) {
        this.categories = categories;
        this.categoriesString = ProjectItemEnum.valueof(categories);
    }

    public void getCategoriesString(String categoriesString) {
        this.categoriesString = categoriesString;
        this.categories = ProjectItemEnum.valueof(categoriesString);
    }

    /**
     * 故障id
     */
    @Column(name = "fault_id")
    @ApiModelProperty(value = "故障id", required = true)
    private Long faultId;
    /**
     * 1 预想故障影响 2历史故障影响
     */
    @Column(name = "type")
    @ApiModelProperty(value = "1 预想故障影响 2历史故障影响")
    private Integer type;

    @Column(name = "score")
    @ApiModelProperty(value = "性能项分数")
    private Double score;

    /**
     * 创建时间
     */
    @Column(name = "created_time")
    @InsertAutoFilling(value = FillingCreateTime.class)
    @ApiModelProperty(value = "创建时间", accessMode = ApiModelProperty.AccessMode.READ_ONLY,
        example = "2010-01-01 00:00:00")
    private Date createdTime;
    /**
     * 更新时间
     */
    @Column(name = "updated_time")
    @UpdateAutoFilling(value = FillingCreateTime.class)
    @ApiModelProperty(value = "最后更新时间", accessMode = ApiModelProperty.AccessMode.READ_ONLY,
        example = "2010-01-01 00:00:00")
    private Date updatedTime;

}
